<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <button id="button">点我</button>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script>

        window.jQuery.ajax = function ({ url, method, body, headers }) {
            return new Promise(function (resolve, reject) {
                let request = new XMLHttpRequest
                request.open(method, url)
                for (let key in headers) {
                    let value = headers[key]
                    request.setRequestHeader(key, value)
                }
                request.onreadystatechange = function () {
                    if (request.readyState === 4) {
                        if (request.status >= 200 && request.status < 300) {
                            resolve.call(undefined, request.responseText)
                        } else if (request.status >= 400) {
                            reject.call(undefined, request)
                        }
                    }
                }
                request.send(body)

            })
        }

        button.addEventListener('click', function () {
            $.ajax(
                {
                    url: '/pay',
                    method: 'POST',
                }).then(
                    (responseText) => {
                        console.log(responseText);

                    },
                    (request) => {
                        console.log(request);
                    }
                )

        })



    </script>

</body>

</html>